package com.escool.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.escool.model.TbGrado;
import com.escool.model.TbNivel;

import com.escool.model.TbTipoPago;
import com.escool.service.CatTipoPagoService;

import com.escool.service.GradosService;
import com.escool.service.NivelesService;
import com.escool.service.RolService;

@Controller
public class CatTipoPagoController {
	
	@Autowired
	CatTipoPagoService catTipoPagoService;

	
	@RequestMapping("showCatTipoPago")
	public String showCatTipoPago(Map<String, Object> map){
		map.put("CatTipoPago", new TbTipoPago());
		map.put("TbTipoPagoList", catTipoPagoService.listTbTipoPago());
		return "/catTipoPago";
	}
	
	@RequestMapping(value = "addCatTipoPago", method = RequestMethod.POST)
	public String addRoles(@ModelAttribute("CatTipoPago") @Valid TbTipoPago tbCatTipoPago, BindingResult result){
		if (!result.hasErrors()) {
			catTipoPagoService.addTbTipoPago(tbCatTipoPago);
			return "redirect:/showCatTipoPago";
		}
		return "";
	}
	
	@RequestMapping(value = "editCatTipoPago", method = RequestMethod.POST)
	public String editRoles(@ModelAttribute("CatTipoPago") @Valid TbTipoPago tbCatTipoPago, BindingResult result){
		if (!result.hasErrors()) {
			catTipoPagoService.editTbTipoPago(tbCatTipoPago);
			return "redirect:/showCatTipoPago";
		}
		return "";
	}
	
	@RequestMapping(value = "deleteCatTipoPago", method = RequestMethod.POST)
	public String delRoles(@ModelAttribute("CatTipoPago") @Valid TbTipoPago tbCatTipoPago, BindingResult result){
		if (!result.hasErrors()) {
			catTipoPagoService.delTbTipoPago(tbCatTipoPago.getIdTipoPago());
			return "redirect:/showCatTipoPago";
		}
		return "";
	}

}
